<?php
include_once "MysqlPdo.php";
namespace app\index\controller;

use think\Controller;
//采集
class Cai extends Controller
{
      public function caiAdd()
      {
              $url="https://www.lagou.com/zhaopin/PHP/?labelWords=label";

              $curl = curl_init($url);
              curl_setopt($curl, CURLOPT_FAILONERROR, true);
              curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
              curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
              curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
              curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
              $result = curl_exec($curl);

              $preg='# <li class="con_list_item default_list" .*>.*<h3>(.*)</h3>.*<span class="money">(.*)</span>.*<!--<i></i>-->(.*).*</li>#isU';

              preg_match_all($preg,$result,$arr);

              foreach ($arr[0] as $value){
                    $books['title']=$arr[1][$value];
                    $books['money']=$arr[2][$value];
                    $books['address']=$arr[3][$value];
                    $books['zhir']=$arr[4][$value];
                    $res=new MysqlPdo();

                    $data=$res->add($arr);

              }
              print_r($data);

              //print_r($arr);
              //echo $result;
      }
}
